package com.zmj.framework.ctrl;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zmj.framework.base.BaseCtrl;
import com.zmj.framework.bean.Sysuser;
import com.zmj.framework.util.ToolsManager;

public class ToolsCtrl extends BaseCtrl {
	private ToolsManager toolsManager;

	public void setToolsManager(ToolsManager toolsManager) {
		this.toolsManager = toolsManager;
	}
	public void sendOnline(HttpServletRequest request, HttpServletResponse response){
		String yhdh=request.getParameter("yhdh");
		if(yhdh!=null&&yhdh.length()>0){
			this.toolsManager.sendOnline(yhdh);
		}
	}
	public void getUsersXml(HttpServletRequest request, HttpServletResponse response) {
		try {
			response.setContentType("text/html; charset=GBK");
			PrintWriter printwriter = response.getWriter();
			response.setContentType("application/xml");
			printwriter.println("<?xml version=\"1.0\" encoding=\"GB2312\"?>");

			List list = this.toolsManager.getOnlineSysusers();
			if (list.size() > 0) {
				Iterator iterator = list.iterator();
				printwriter.println("<root>");
				while (iterator.hasNext()) {
					Sysuser user = (Sysuser) iterator.next();
					printwriter.println("<user>");
					printwriter.println("<yhdh>" + user.getYhdh() + "</yhdh>");
					printwriter.println("<yhmc>" + user.getYhmc() + "</yhmc>");
					printwriter.println("</user>");
				}
				printwriter.println("</root>");
			} else {
				printwriter.println("<root>");
				printwriter.println("</root>");
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
}